package server.business.process;



import org.json.JSONException;
import org.json.JSONObject;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class process extends HttpServlet {
//所有的接受的是原生的HttpServletRequest和HttpServletResponse，以及处理的数据str,返回的是json字符串，对这个字符串进行解析
//然后获得相关的数据，data中是返回前端的数据，opt中操作的类型（update）,msg是需要操作的数据{"data":"","opt":"","msg":""}
//整体的操作是先对传进来的字符串进行解析操作，执行操作，然后对返回的数据进行封装。
    public String getsomemsg(HttpServletRequest req, HttpServletResponse resp,String str) throws JSONException {

        JSONObject jsonObject = new JSONObject(str);

        return "{data:"+ str +",opt:"+ "getmsg" +",msg:"+ str+"}";
    }


    public String addformmsg1(HttpServletRequest req, HttpServletResponse resp,String str) throws JSONException{
//        System.out.println("req"+req.);
        JSONObject jsonObject = new JSONObject(str);
//        System.out.println("获取的json"+req.getParameter("json"));
        JSONObject jsonObject1 = new JSONObject(req.getParameter("json"));
        jsonObject.put("name",jsonObject1.opt("name"));
        jsonObject.put("idnum",jsonObject1.opt("idnum"));
        jsonObject.put("age",jsonObject1.opt("age"));
        jsonObject.put("sex",jsonObject1.opt("sex"));
        jsonObject.put("hosid",jsonObject1.opt("hosid"));
        jsonObject.put("badid",jsonObject1.opt("badid"));
        String data = null;
        String opt = "addform";
        String msg = jsonObject.toString();
//        String goal = ;
        return "{data:"+ data +",opt:"+ opt +",msg:"+ msg+"}";
    }


    public String addformmsg2(HttpServletRequest req, HttpServletResponse resp,String str) throws JSONException{
//        System.out.println("req"+req.);
        JSONObject jsonObject = new JSONObject(str);
//        System.out.println("获取的json"+req.getParameter("json"));
        JSONObject jsonObject1 = new JSONObject(req.getParameter("json"));
        jsonObject.put("bloodtype",jsonObject1.opt("bloodtype"));
        jsonObject.put("data",jsonObject1.opt("data"));

        String data = null;
        String opt = "addform";
        String msg = jsonObject.toString();
//        String goal = ;
        return "{data:"+ data +",opt:"+ opt +",msg:"+ msg+"}";
    }
    public String addformmsg3(HttpServletRequest req, HttpServletResponse resp,String str) throws JSONException{
//        System.out.println("req"+req.);
        JSONObject jsonObject = new JSONObject(str);
//        System.out.println("获取的json"+req.getParameter("json"));
        JSONObject jsonObject1 = new JSONObject(req.getParameter("json"));
        jsonObject.put("bloodtime",jsonObject1.opt("bloodtime"));
        jsonObject.put("jiliang",jsonObject1.opt("jiliang"));
        jsonObject.put("blooddate",jsonObject1.opt("blooddate"));
        String data = null;
        String opt = "addform";
        String msg = jsonObject.toString();
//        String goal = ;
        return "{data:"+ data +",opt:"+ opt +",msg:"+ msg+"}";
    }



    public String chargeform1(HttpServletRequest req, HttpServletResponse resp,String str) throws JSONException{
        JSONObject jsonObject = new JSONObject(str);
        jsonObject.put("charge","ok");
        JSONObject jsonObject1 = new JSONObject(req.getParameter("json"));
        jsonObject.put("name",jsonObject1.opt("name"));
        jsonObject.put("idnum",jsonObject1.opt("idnum"));
        jsonObject.put("age",jsonObject1.opt("age"));
        jsonObject.put("sex",jsonObject1.opt("sex"));
        jsonObject.put("hosid",jsonObject1.opt("hosid"));
        jsonObject.put("badid",jsonObject1.opt("badid"));
        jsonObject.put("bloodtype",jsonObject1.opt("bloodtype"));
        jsonObject.put("bloodtype",jsonObject1.opt("data"));
        jsonObject.put("bloodtime",jsonObject1.opt("bloodtime"));
        jsonObject.put("jiliang",jsonObject1.opt("jiliang"));
        jsonObject.put("blooddate",jsonObject1.opt("blooddate"));

        String data = null;
        String opt = "examine";
        String msg = jsonObject.toString();
//        String goal = ;
        return "{data:"+ data +",opt:"+ opt +",msg:"+ msg+"}";
    }
    public String chargeform2(HttpServletRequest req, HttpServletResponse resp,String str) throws JSONException{
        JSONObject jsonObject = new JSONObject(str);
        jsonObject.put("charge","ok");
        JSONObject jsonObject1 = new JSONObject(req.getParameter("json"));
        jsonObject.put("name",jsonObject1.opt("name"));
        jsonObject.put("idnum",jsonObject1.opt("idnum"));
        jsonObject.put("age",jsonObject1.opt("age"));
        jsonObject.put("sex",jsonObject1.opt("sex"));
        jsonObject.put("hosid",jsonObject1.opt("hosid"));
        jsonObject.put("badid",jsonObject1.opt("badid"));
        String data = null;
        String opt = "examine";
        String msg = jsonObject.toString();
//        String goal = ;
        return "{data:"+ data +",opt:"+ opt +",msg:"+ msg+"}";
    }


}
